<?php
namespace Docs\Controller; 
use Think\Controller;
class IndexController extends Controller{
	
	public function index(){
		if(!isset($_GET['app'])){
			$topnavkeys = array_keys(C('DocsTopnav'));
			$_GET['app'] = $topnavkeys[0];  //默认获取第一个
		}
		
		
		$this->leftmenu = $this->_get_leftmenu($_GET['app']); //获取左菜单
		
		if(!isset($_GET['method'])){
			$_GET['method'] = $this->leftmenu[0];
		}
		
		$this->doc = $this->_self_get_doc($_GET['app'], $_GET['method']);
		
		$this->display();
	}
	
	/**
	 * 
	 * @param string $app
	 */
	private function _get_leftmenu($app){
		$C_LAYER = C('DEFAULT_C_LAYER');  //控制器后缀
		$apibaseapp = C('DocsBaseApp');
		$classname = $apibaseapp."\\".$C_LAYER."\\".$app.$C_LAYER; //实例化当前的类名
		$curclass = new $classname();
		$myMethods = get_class_methods($curclass);
		
		//过滤一下方法
		$filters = array(
				'__construct',
				'display',
				'show',
				'fetch',
				'buildHtml',
				'theme',
				'assign',
				'__set',
				'get',
				'__get',
				'__isset',
				'__call',
				'error',
				'success',
				'ajaxReturn',
				'redirect',
				'__destruct',
				'_initialize',
				'checkToken',
		);
		foreach($myMethods as $my){
			if(!in_array($my,$filters)){
				$leftmenu[] = $my;
			}		
		}
		return $leftmenu;
	}
	
	
	private function _self_get_doc($app,$method){
		$C_LAYER = C('DEFAULT_C_LAYER');  //控制器后缀
		$apibaseapp = C('DocsBaseApp');
		$classname = $apibaseapp."\\".$C_LAYER."\\".$app.$C_LAYER; //实例化当前的类名
		
		return _get_doc($classname, $method,$app);
	}
	
	
	
	
}